package cn.tedu.service;

import cn.tedu.pojo.Car;

import java.sql.*;

public class TestJDBC {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql:///mydemo1", "root", "root");
        String sql ="select * from Car where name=?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1,"凯迪拉克CT5");
        ResultSet rt = ps.executeQuery();

        Car c=new Car();
        while (rt.next()){
            String name =rt.getNString(1);
            String color =rt.getNString(2);
            Double price =rt.getDouble(3);
//            System.out.println(name+"\t"+color+"\t"+price);
            c.setName(name);
            c.setColor(color);
            c.setPrice(price);
            System.out.println(c);
        }
        rt.close();
        ps.close();
        conn.close();

    }
}
